package com.itheima.socket.sendUDP;

import java.net.DatagramPacket;
import java.net.DatagramSocket;

public class Server {
    public static void main(String[] args) throws Exception {
        System.out.println("准备接数据");
        // 创建服务端对象
        DatagramSocket socket = new DatagramSocket(6666);

        // 创建一个数据包对象，用于接收数据
        byte[] buf = new byte[1024];
        DatagramPacket packet = new DatagramPacket(buf, buf.length);

        // 开始接受
        socket.receive(packet);

        int len = packet.getLength();
        String rs = new String(buf, 0, len);
        System.out.println(rs);
        System.out.println(packet.getAddress().getHostAddress());
        System.out.println(packet.getPort());
    }
}
